package net.oschina.app.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;

import net.oschina.app.R;
import net.oschina.app.base.BaseActivity;
import net.oschina.app.bean.ActiveBean;
import net.oschina.app.bean.PraiseBean;
import net.oschina.app.fragment.DetailAtMeFragment;
import net.oschina.app.fragment.DetailChatFragment;
import net.oschina.app.fragment.DetailCommentFragment;
import net.oschina.app.fragment.DetailFriendsFragment;
import net.oschina.app.fragment.DetailPraiseFragment;
import net.oschina.app.interf.FragmentType;

/**
 * Created by elf on 2017/1/18.
 */

public class DetailFragmentActivity extends BaseActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);
        initActionBar();
    }

    private void initActionBar() {
        String displayType = getIntent().getStringExtra(FragmentType.FRAGMENT_TYPE);
        if (!TextUtils.isEmpty(displayType)) {
            int actionBarTitle = 0;
            Fragment fragment = null;
            switch (displayType) {
                case FragmentType.TYPE_FRIENDS_DETAIL://好友圈详情
                    actionBarTitle = R.string.actionbar_title_tweet;
                    fragment = new DetailFriendsFragment();
                    ActiveBean friends = (ActiveBean) getIntent().getSerializableExtra("bean");
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("bean",friends);
                    fragment.setArguments(bundle);
                    break;
                case FragmentType.TYPE_ME_ATME_DETAIL:
                    actionBarTitle = R.string.actionbar_title_tweet;
                    fragment = new DetailAtMeFragment();
                    ActiveBean atmebean = (ActiveBean) getIntent().getSerializableExtra("bean");
                    Bundle atMeBundle = new Bundle();
                    atMeBundle.putSerializable("atmebean",atmebean);
                    fragment.setArguments(atMeBundle);
                    break;
                case FragmentType.TYPE_ME_COMMENT_DETAIL:
                    actionBarTitle = R.string.actionbar_title_tweet;
                    fragment = new DetailCommentFragment();
                    ActiveBean commentbean = (ActiveBean) getIntent().getSerializableExtra("bean");
                    Bundle commentBundle = new Bundle();
                    commentBundle.putSerializable("commentbean",commentbean);
                    fragment.setArguments(commentBundle);
                    break;
                case FragmentType.TYPE_ME_GOODS_DETAIL:
                    actionBarTitle = R.string.actionbar_title_tweet;
                    fragment = new DetailPraiseFragment();
                    PraiseBean.MytweetBean mytweetBean  = (PraiseBean.MytweetBean)
                            getIntent().getSerializableExtra("bean");
                    Bundle praiseBundle = new Bundle();
                    praiseBundle.putSerializable("mytweetBean",mytweetBean);
                    fragment.setArguments(praiseBundle);
                    break;
                case FragmentType.TYPE_ME_NEWMESSAGE_DETAIL:
                case FragmentType.TYPE_ME_FANS_DETAIL:
                case FragmentType.TYPE_ME_FOLLOWING_DETAIL:
                    String title = getIntent().getStringExtra("title");
                    mActionBar.setTitle(title);
                    fragment = new DetailChatFragment();
                    break;
                default:
                    finish();
                    break;
            }
            if (actionBarTitle != 0) {
                setActionBarTitle(actionBarTitle);
            }
            FragmentTransaction ft = getSupportFragmentManager()
                    .beginTransaction();
            ft.replace(R.id.container_open_soft, fragment).commit();
        }
    }

}
